package com.tomato.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tomato.order.VO.ResultVO;
import com.tomato.order.entity.Info;
import com.tomato.order.entity.Support;
import com.tomato.order.mapper.InfoMapper;
import com.tomato.order.mapper.SupportMapper;
import com.tomato.order.util.R;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/info")
public class InfoController {
    @Resource
    private InfoMapper infoMapper;

    @RequestMapping("/list")
    public List list() {
        return infoMapper.selectList(new QueryWrapper<Info>().orderByDesc("id"));
    }

    @RequestMapping("/create")
    public ResultVO create(Info info) {
        int result = infoMapper.insert(info);
        if (result == 1) {
            return R.success("添加成功！");
        } else {
            return R.error(1, "添加失败！");
        }
    }

    @RequestMapping("/delete")
    public ResultVO delete(@RequestParam("id") String id) {
        int result = infoMapper.delete(new QueryWrapper<Info>().eq("id", id));
        if (result == 1) {
            return R.success("删除成功！");
        } else {
            return R.error(1, "删除失败！");
        }
    }
}